package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import io.netty.handler.codec.serialization.ObjectEncoder;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {

    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    @Select("select id from setmeal_dish where dish_id = #{id}")
    List<SetmealDish> getByDishId(Long id);

    List<SetmealDish> getByDishIdAndStatus(Long id, Integer status);

    @AutoFill(OperationType.INSERT)
    void insertSetmeal(Setmeal setmeal);

    void insertSetmealDishes(List<SetmealDish> setmealDishes);

    Page<SetmealVO> queryPage(SetmealPageQueryDTO setmealPageQueryDTO);

    SetmealVO getBySetmealId(Long id);

    @Select("select * from setmeal_dish where setmeal_id = #{id}")
    List<SetmealDish> getBySetmealIdForDishes(Long id);

    List<Setmeal> getByIds(List<Long> ids);

    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    @Delete("delete from setmeal_dish where setmeal_id = #{id}")
    void deleteDishesById(Long id);

    @Select("select dish_id from setmeal_dish where setmeal_id = #{id}")
    List<Long> queryDishIds(Long id);

    void deleteSetmealByIds(List<Long> ids);

    List<Setmeal> list(Setmeal setmeal);

    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);

    @Select("select * from setmeal where id = #{id}")
    Setmeal getById(Long id);

    Integer countByMap(Map<String, Object> map);
}
